<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="keywords" content="remote machines, Git, GitHub" />
    <meta name="description" content="Lecture introducing remote machines and version control using Git." />
    <title>BCB 546X -- 19 Jan 2017</title>
    <style>
      @import url(https://fonts.googleapis.com/css?family=Droid+Serif);
      @import url(https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz);
      @import url(https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic);

      body {
        font-family: 'Droid Serif';
      }
      h1, h2, h3 {
        font-family: 'Yanone Kaffeesatz';
        font-weight: 400;
        margin-bottom: 0;
      }
      .remark-slide-content h1 { font-size: 3em; }
      .remark-slide-content h2 { font-size: 2em; }
      .remark-slide-content h3 { font-size: 1.6em; }
      .footnote {
        position: absolute;
        bottom: 3em;
      }
      li p { line-height: 1.25em; }
      .red { color: #fa0000; }
      .large { font-size: 2em; }
      a, a > code {
        color: rgb(249, 38, 114);
        text-decoration: none;
      }
      code {
        background: #e7e8e2;
        border-radius: 5px;
      }
      .remark-code, .remark-inline-code { font-family: 'Ubuntu Mono'; }
      .remark-code-line-highlighted     { background-color: #373832; }
      .pull-left {
        float: left;
        width: 47%;
      }
      .pull-right {
        float: right;
        width: 47%;
      }
      .pull-right ~ p {
        clear: both;
      }
      #slideshow .slide .content code {
        font-size: 0.8em;
      }
      #slideshow .slide .content pre code {
        font-size: 0.9em;
        padding: 15px;
      }
      .inverse {
        background: #272822;
        color: #777872;
        text-shadow: 0 0 20px #333;
      }
      .inverse h1, .inverse h2 {
        color: #f3f3f3;
        line-height: 0.8em;
      }
      /* Two-column layout */
      .left-column {
        color: #777;
        width: 20%;
        height: 92%;
        float: left;
      }
        .left-column h2:last-of-type, .left-column h3:last-child {
          color: #000;
        }
      .right-column {
        width: 75%;
        float: right;
        padding-top: 1em;
      }
    </style>
  </head>
  <body>
    <textarea id="source">

class: center, middle

# More Fun with Git

???

Notes for the _first_ slide!



---

# &#x2665; Git &#x2665;

## Creating a Repository

Let's create a new Git repository and host it on GitHub using our accounts (for the demo, 
I will create the repo in the [EEOB-BioData](https://github.com/EEOB-BioData) organization
so that everyone will have easy access to it).

<br>

--

But first, let's tell Git who you are

```
$ git config --global user.name "Ada Lovelace"
$ git config --global user.email "adal@analyticalengine.com"
```


---

# &#x2665; Git &#x2665;

### Some helpful commands for your new repository

--

Initialize a new Git repository

```
$ git init
```

--

After a file has been added or modified, you can stage the file 

```
$ git add README.md
```

--

Commit the file to your local repository and write a message

```
$ git commit -m "initial commit (README.md)"
```


---

# &#x2665; Git &#x2665;

### Some helpful commands for your new repository

After you have made your commit, the repository is up-to-date locally. Next you need to connect
your local repo to the remote.

--

Add the remote

```
$ git remote add origin git@github.com:username/repo-name.git
```

--

Push your snapshot to the remote

```
$ git push -u origin master
```

---

# &#x2665; Git &#x2665;

## Git can be challenging

<br>

* What do you find confusing? 

* What did you struggle with when creating a repository?

* What do you think would be helpful to overcome these challenges?

---

# Git Conceptual Road Map

<div style="text-align:center"><img src="http://blog.podrezo.com/wp-content/uploads/2014/09/git-operations.png" alt="gource" width="700" /></div>

(image source [http://blog.podrezo.com/git-introduction-for-cvssvntfs-users](http://blog.podrezo.com/git-introduction-for-cvssvntfs-users/))


---

# Git Best Practices

* Commit often. Keep commits small and frequent. This also helps you have informative commit messages

--

* Make sure every commit "works". Never commit if it doesn't compile, runs with errors, 
or requires files that only exist in your workspace. Since commits are snapshots, this should mean a working snapshot.

--

* Write commit messages that will be readable and useful to others and *future-you*. (This is really difficult.) Also, remember when your repository is public, anyone can see your commit messages.

--

<div style="text-align:center"><a href="https://twitter.com/kcranstn/status/370914072511791104?ref_src=twsrc%5Etfw"><img src="images/tweet.png" alt="gource" width="450" /></a></div>

--

* Use multiple branches. This is one of Git's most powerful features and enhances collaboration and reproducibility. You should
also decide on a [workflow](https://www.atlassian.com/git/tutorials/comparing-workflows) (like [this](https://guides.github.com/introduction/flow/) or [this](http://nvie.com/posts/a-successful-git-branching-model/)).

---

# Git Best Practices

* Pull from the remote before you do anything in your repository. This reduces potential merge conflicts. So before you make
changes to any files `git pull`, after you make a commit and before you push `git pull`. 

--

* Don't commit unnecessary files. Often these are files that may be generated by your project 
and can lead to merge conflicts. 
You can keep these files in your working directory without being tracked using the `.gitignore` file
(or the `~/.gitignore_global` file in your home directory).

--

* Review your changes before committing. 

--

* Use aliases. You can add specific aliases for Git commands in the `.gitconfig` file that lives in your home directory. 

```
[alias]
hist = log --graph --pretty=format:'%h %ad | %s%d [%an]' --date=short
last = log -1 HEAD
ci = commit
st = status
```

---

# Markdown

[Markdown](https://daringfireball.net/projects/markdown/) is a text-based mark-up language that is easily rendered
into HTML

--

* It has become a staple of reproducible science: 

--

    * it can be rendered on GitHub (also Bitbucket & GitLab) and makes online repositories more readable and accessable
--

    * it is used as a notebook interface for R ([Rmarkdown](http://rmarkdown.rstudio.com/))
--

    * it is used as the markup language for [Jupyter](http://jupyter.org/) notebooks, which provide a notebook interface for many languages, including Python and R
--

* There are some freely available editors that make writing in Markdown pretty easy

    * Windows and Linux: [REMARKABLE](https://remarkableapp.github.io/)
    * Mac OSX: [MacDown](http://macdown.uranusjr.com/)

--

* I made all my slides using Markdown and a HTML template called [Remark](https://remarkjs.com)

---

# Markdown

## Let's see some Markdown

* It is recommended that all README files on web-based Git hosts be written using Markdown

--

* The file extension for a Markdown file is `.md`

--

* I will demonstrate in MacDown with our `README.md` file for `Week_2`

---

# Your Repository

Let's take some time to make sure everyone has been able to create a repository and push files to GitHub

<br>

If you were successful in doing this already, please help your classmates. 

---

# Get Help

## No matter the problem (with Git or anything else in this class), someone else has encountered it already.

Google is an immensely powerful tool for troubleshooting computational problems

--

If you can articulate your problem in the form of a Google search query, you will likely find the answer online

--

These will primarily be on [Stack Overflow](http://stackoverflow.com/), like my [recent search](http://stackoverflow.com/questions/7155870/why-unicode-character-for-hearts-symbol-fails-with-html) for how to include 
Unicode emoji characters in my Markdown presentation &#x1F60E; &#x1F4BB;

--

If your problem is unique, you can always submit a question on Stack Overflow 

---

# Working with Others

Once you start working with other people on the same repository, you will encounter some scenarios that we haven't yet covered.

--

*What happens when two people commit changes to the repository at the same time?*

--

*What happens when two people commit changes to the same part of the same file at the same time?!?*

--

*What if I really disagree with the changes someone made to the repository?*

--

<br>

Let's demonstrate what happens when we merge...

???

to revert (hard) use `git reset`

can checkout previous commits temporarily.

---

# Git Collaboration

### Now that we all have repositories on GitHub, let's collaborate!

* Get into groups of 2-3. 

* Give your collaborators access (push rights) to your repository

* Clone your collaborator's repository

* Add and edit files in your collaborator's repository

* Commit and push those changes to the remote

---

# Git GUIs

## Graphical user interfaces for Git

There are several [GUI tools](https://git-scm.com/download/gui/linux) for working with Git

These tools may be very helpful for doing things that you don't do every day (when it's difficult
to remember the command)

They also provide nice ways to visualize your repository tree and `diff` commits, etc.

I like [SourceTree](https://www.sourcetreeapp.com/).

---

# GitHub Pages 

### GitHub provides hosting for websites ([https://pages.github.com](https://pages.github.com/))

* You can create a *free* website hosted on GitHub simply by creating a repository in your account called
`username.github.io`

--

* You can create a website for any GitHub project repository, simply by enabling GitHub Pages in your settings

--

* My lab website ([http://phyloworks.org](http://phyloworks.org)) is hosted on [GitHub](https://github.com/phyloworks/phyloworks.github.io), using a [Bootstrap](http://getbootstrap.com/) CSS template.
If you [purchase](https://www.namecheap.com/) your own domain, it is simple to [redirect](https://help.github.com/articles/using-a-custom-domain-with-github-pages/) your GitHub Pages site to the new domain. 



    </textarea>
    <script src="https://gnab.github.io/remark/downloads/remark-latest.min.js" type="text/javascript">
    </script>
    <script>
      var hljs = remark.highlighter.engine;
    </script>
    <script src="remark.language.js"></script>
    <script>
      var slideshow = remark.create({
          highlightStyle: 'monokai',
          highlightLanguage: 'tex',
          highlightLines: true
        }) ;
    </script>
    <script>
      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', 'UA-44561333-1']);
      _gaq.push(['_trackPageview']);

      (function() {
        var ga = document.createElement('script');
        ga.src = 'https://ssl.google-analytics.com/ga.js';
        var s = document.scripts[0];
        s.parentNode.insertBefore(ga, s);
      }());
    </script>
  </body>
</html>
